package com.muh.controller;

import com.muh.entity.User1;
import com.muh.service.User1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (User1)表控制层
 *
 * @author makejava
 * @since 2025-07-14 16:16:34
 */
@RestController
@RequestMapping("user1")
public class User1Controller {
    /**
     * 服务对象
     */
    @Autowired
    private User1Service user1Service;

    /**
     * 分页查询
     *
     * @param user1 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<User1>> queryByPage(User1 user1, PageRequest pageRequest) {
        return ResponseEntity.ok(this.user1Service.queryByPage(user1, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseEntity<User1> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.user1Service.queryById(id));
    }

    @RequestMapping("/getUserByName")
    public List<User1> getUserByName(@RequestParam("name")String name) {
        List<User1> user1List= this.user1Service.getUserByName(name);
        return user1List;
    }
    /**
     * 新增数据
     *
     * @param user1 实体
     * @return 新增结果
     */
    @PostMapping("/insert")
    public int insert(@RequestBody User1 user1) {
        return this.user1Service.insert(user1);
    }
    @PostMapping("/insertBatch")
    public int insertBatch(@RequestBody List<User1> user1List) {
        return this.user1Service.insertBatch(user1List);
    }
    /**
     * 编辑数据
     *
     * @param user1 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public ResponseEntity<User1> update(@RequestBody User1 user1) {
        return ResponseEntity.ok(this.user1Service.update(user1));
    }

    @PostMapping("/insertOrUpdateBatch")
    public int insertOrUpdateBatch(@RequestBody List<User1> user1List) {
        return this.user1Service.insertOrUpdateBatch(user1List);
    }
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteById")
    public boolean deleteById(@RequestParam("id")Integer id) {
        return this.user1Service.deleteById(id);
    }

}

